* NOTE: change first line ("use") command based on your own directory

use "/Users/mtarsi/Desktop/UMAS0013_OUTPUT.dta"

set more off

svyset [pw=weight]

recode q1-q6a_7 q6b_1-q6b_7 q7_1-q14 (9=.)

*Vote w leaners
recode q5 9=., gen(withleaners)
label values withleaners Q5
replace withleaners=1 if q5a==1
replace withleaners=2 if q5a==2

*campaign contact
* Campaign Contact Info: Walsh
gen walshcontact=1 if q6a_1==1
replace walshcontact=2 if q6a_2==1
replace walshcontact=3 if q6a_3==1
replace walshcontact=4 if q6a_4==1
replace walshcontact=5 if q6a_5==1
label define contact 1 "Phone" 2 "In-person" 3 "Online" 4 "Not contacted" 5 "DK/Don't Remember"
label values walshcontact contact
*Campaign Contact Info: Connolly
gen connollycontact=1 if q6b_1==1
replace connollycontact=2 if q6b_2==1
replace connollycontact=3 if q6b_3==1
replace connollycontact=4 if q6b_4==1
replace connollycontact=5 if q6b_5==1
label values connollycontact contact

gen contact=1 if walshcontact<3
replace contact=2 if connollycontact<3
replace contact=3 if walshcontact<3 & connollycontact<3

label define contact2 1 "Contacted by Walsh" 2 "Contacted by Connolly" 3 "Contacted by both"
label values contact contact2

ren d1 gender

ren d2 age
*agecat
recode age 18/34=1 35/54=2 55/99=3 999=., gen(agecat)
label define age 1 "18 to 34" 2 "35 to 54" 3 "55 over"
label val agecat age

ren d3 edu
recode edu 1/2=1 3=2 4=3 5=4  6/99=., gen(educat)
label define edu 1 "hs or less" 2 "some college" 3 "college grad" 4 "post grad"
label val educat edu


ren d4 ethnicity

* RACE CAT
gen white=d5_1 if ethnicity==2
recode white .=0
gen black=d5_2
recode black .=0

ren d6 married 

ren d7 parent
recode parent 9=.

ren d7a parent_bosschool
recode parent_bosschool 1=1 2=.

ren d8 ownrent
recode ownrent 3/9=.

ren d8a yearsinboston
gen yearscat=yearsinboston
recode yearscat 0/10=1 11/99=2 998/999=.
label define years 1 "under 10 years" 2 "over 10 years"
label val yearscat years

ren d9a partyreg
recode partyreg 5/6=. 4=3

ren d9 partyid
gen pid3=partyid
recode pid3 4/9=.
label define pid 1 "Dem" 2 "Rep" 3 "Ind"
label val pid3 pid

ren d10 ideo
recode ideo 4/9=.

ren d11 union
recode union 3/9=.
label define union 1 "union HH" 2 "non union HH"
label val union union


ren d12 zipcode

ren d13 income

*income cat
gen incomecat=income
recode incomecat 1/2=1 3/4=2 5=3  9=4 8=.
label define income 1 "under 50k" 2 "50k to 100k" 3 "over 100k" 4 "refused"
label val incomecat income

* Prelim vote
recode q3a 1/4=11 6=11 8=11 12=11 13/99=., gen(prelimvote)
label define prelim 5 "Connolly" 7 "Richie" 10 "Walsh" 11 "Other"
label values prelimvote prelim



*CROSSTABS

*BINARY VARIABLES
* VOTE CHOICE

recode withleaners 1=1 2/9=0, gen(vote_walsh)
recode withleaners 2=1 1=0 3/9=0, gen(vote_connolly)


* MENINO ON BALLOT
recode q11 1=1 2/9=0, gen(hypovote_walsh)
recode q11 1=0 2=1 3/9=0, gen(hypovote_connolly)
recode q11 1/2=0 3=1 4/9=0, gen(hypovote_menino)


*CASINO
recode q13 1=1 2/9=0, gen(yescasino)
recode q13 1=0 2=1 3/9=0, gen(nocasino)

*POLICE PAY

recode q14 1=1 2/9=0, gen(yespay)
recode q14 1=0 2=1 3/9=0, gen(nopay)

gen likelyvoters=q4
recode likelyvoters 10=1 1/9=0 98/99=0

* DEMOS OF LVs
svy: tab gender  if likelyvoters==1
svy: tab agecat  if likelyvoters==1
svy: tab educat  if likelyvoters==1
svy: tab yearscat  if likelyvoters==1
svy: tab union  if likelyvoters==1
svy: tab white  if likelyvoters==1
svy: tab partyreg  if likelyvoters==1
svy: tab ideo  if likelyvoters==1
svy: tab ownrent if likelyvoters==1
svy: tab yearscat if likelyvoters==1


* CROSSTABS TABLESTAT COMMANDS

* vote choice

tablemat vote_walsh vote_connolly if likelyvoters==1 [aw=weight], by( gender agecat educat yearscat union white partyreg ideo parent_bosschool ownrent contact prelimvote incomecat) st(mean)

* menino on ballot
tablemat hypovote_walsh hypovote_connolly hypovote_menino if likelyvoters==1 [aw=weight], by(gender agecat educat yearscat union white partyreg ideo parent_bosschool ownrent contact prelimvote incomecat) st(mean)

*casino -- approve
tablemat yescasino if likelyvoters==1 [aw=weight], by(gender agecat educat yearscat union white partyreg ideo parent_bosschool ownrent contact prelimvote incomecat) st(mean)

*police pay -- approve
tablemat yespay if likelyvoters==1 [aw=weight], by(gender agecat educat yearscat union white partyreg ideo parent_bosschool ownrent contact prelimvote incomecat) st(mean)



